package com.ls.controller;

import com.ls.service.DataService;
import com.ls.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * @author ls
 * @version v1.0
 * @description 统计网站数据
 * @date 2021/8/24 0:28
 */
@Controller
public class DataController {

    @Autowired
    private DataService dataService;

    @GetMapping("/data")
    public String toDatePage() {
        return "site/admin/data";
    }

    @PostMapping("/data/uv")
    @ResponseBody
    public R countUv(@DateTimeFormat(pattern = "yyyy-MM-dd") Date start,
                     @DateTimeFormat(pattern = "yyyy-MM-dd") Date end) {
        long uvResult = dataService.countUv(start, end);
        return R.ok().put("data", uvResult);
    }

    @PostMapping("/data/dau")
    @ResponseBody
    public R countDau(@DateTimeFormat(pattern = "yyyy-MM-dd") Date start,
                      @DateTimeFormat(pattern = "yyyy-MM-dd") Date end) {
        long dauResult = dataService.countDau(start, end);
        return R.ok().put("data", dauResult);
    }

}
